import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestDemo {
    public static void main(String[] args) {
        Frame frame = new Frame();
        frame.setBounds(300,300,600,300);//设置初始大小和显示位置
        frame.setBackground(Color.GRAY);//设置背景颜色
        frame.setLayout(new GridLayout(2,1));//设置上下的大布局，2行1列
        Panel panel1 = new Panel(new BorderLayout());//上方大局
        Panel panel2 = new Panel(new GridLayout(2,1));//上方的2行1列

        Panel panel3 = new Panel(new BorderLayout());//下方大局
        Panel panel4 = new Panel(new GridLayout(2,2));//下方的表格

        panel1.add(new Button("button-east"),BorderLayout.EAST);
        panel1.add(new Button("button-west"),BorderLayout.WEST);
        panel2.add(new Button("p2-button-1"));
        panel2.add(new Button("p2-button-2"));
        panel1.add(panel2,BorderLayout.CENTER);
        //上部分结束
        //4.for
        for (int i = 0; i < 4; i++) {
            panel4.add(new Button("p4-button-"+i));
        }
//        panel4.add(new Button("p4-button-1"));
//        panel4.add(new Button("p4-button-2"));
//        panel4.add(new Button("p4-button-3"));
//        panel4.add(new Button("p4-button-4"));
        panel3.add(new Button("p3-button-east"),BorderLayout.EAST);
        panel3.add(new Button("p3-button-west"),BorderLayout.WEST);
        panel3.add(panel4,BorderLayout.CENTER);
        frame.add(panel1);
        frame.add(panel3);
        //设置监听窗口事件
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(0);
            }
        });
        frame.setVisible(true);
    }
}
